import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeSet;

public class TreeSetPractice {

    public static void main(String[] args) {
        //创建一个TreeSet对象，存储Person对象，按照成绩对学生进行排序
        //创建一个Scanner 对象，对键盘监听录入

        Comparator<Person> comparator = new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
                return (int) (o2.getMath()+o2.getChinese()+o2.getEnglish()-o1.getMath()-o1.getChinese()-o1.getEnglish());
            }
        };
        TreeSet<Person> treeSet = new TreeSet<>(comparator);
        Scanner sc = new Scanner(System.in);
        for(int i=0;i<3;i++){
            System.out.println("请输入"+(i+1)+"个学生姓名：");
            //线程阻塞
            String name = sc.next();

            System.out.println("请输入学生语文成绩：");
            double chinesescore = sc.nextDouble();
            System.out.println("请输入学生数学成绩：");
            double mathscore = sc.nextDouble();
            System.out.println("请输入学生英语成绩：");
            double englishscore = sc.nextDouble();
            Person person = new Person(name, chinesescore, mathscore, englishscore);
            treeSet.add(person);

        }

        for (Person person : treeSet){
            System.out.println(person);
        }
    }
}
